<?php
$config = include('./config.php');
$ipsAllow = array('113.161.74.215','127.0.0.1');
$myCk = isset($_COOKIE['ssgtest']) ? $_COOKIE['ssgtest'] : '';
switch($config['env'])
{
    case 'standby-internal':
        if($myCk == 'ceacca579d7c9cf940f1a516dc18652c' && in_array($_SERVER['REMOTE_ADDR'], $ipsAllow)){
            $envFolder     = '/standby';
        }else{
            $envFolder     = '/live';            
        }
        break;
    case 'standby':
        $envFolder = '/standby';        
        break;
    case 'live-internal':
        if($myCk == 'ceacca579d7c9cf940f1a516dc18652c' && in_array($_SERVER['REMOTE_ADDR'], $ipsAllow)){
            $envFolder = '/live';
        }else{
            $envFolder = '/standby';            
        }
        break;
    case 'live':
        $envFolder = '/live';
        break;
    default:
        $envFolder = '';
}

defined('APPLICATION_PATH') 
    || define('APPLICATION_PATH', 
              realpath(dirname(__FILE__) . "/..{$envFolder}/application")); 
//define('APPLICATION_ENV', 'local'); 			  
defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); 

define('PLATFORM','');
define('ROOT_PATH',realpath(dirname(dirname(__FILE__))));   

//define('VERSION_PATH','');
//define('CONFIG_PATH', APPLICATION_PATH . '/configs' . VERSION_PATH);
define('CONFIG_PATH', APPLICATION_PATH . '/configs' );
//define('WEB_PATH',realpath(dirname(dirname(__FILE__))));
                                 
define('LIBRARY_PATH',dirname(dirname(__FILE__)) . $envFolder . '/library');
set_include_path(implode(PATH_SEPARATOR, array( 
    LIBRARY_PATH, get_include_path(), 
))); 
require_once 'Zend/Application.php' ;
$application = new Zend_Application( 
    APPLICATION_ENV, 
    APPLICATION_PATH . '/configs/application.ini' 
); 
$application->bootstrap()->run();

function pr($data, $die = true)
{
    $allowIp = array('127.0.0.1','192.168.1.73');
    if (in_array($_SERVER["REMOTE_ADDR"],$allowIp)) {
        $numargs = func_num_args();
        $data = func_get_args();
        if($numargs == 1){
            $data = $data[0];
        }

        $trace = debug_backtrace();
        $caller = array_shift($trace);
        echo '<pre>';
        echo "called by [" . $caller['file'] . "] line: " . $caller['line'] . "\n";
        print_r($data);
        if ($die) {
            die();
        }
    }
}
